/*
 * @lc app=leetcode.cn id=155 lang=cpp
 *
 * [155] 最小栈
 */

#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <limits.h>
using namespace std;

// @lc code=start
class MinStack {
   public:
    stack<int> value_stack;
    stack<int> mini_stack;

    MinStack() {}

    void push(int val) {
        if (value_stack.empty()) {
            int minimum = val;
            value_stack.push(val);
            mini_stack.push(minimum);
        } else {
            int minimum = (mini_stack.top() < val) ? mini_stack.top() : val;
            value_stack.push(val);
            mini_stack.push(minimum);
        }
    }

    void pop() {
        value_stack.pop();
        mini_stack.pop();
    }

    int top() {
        return value_stack.top();
    }

    int getMin() {
        return mini_stack.top();
    }
};

/**
 * Your MinStack object will be instantiated and called as such:
 * MinStack* obj = new MinStack();
 * obj->push(val);
 * obj->pop();
 * int param_3 = obj->top();
 * int param_4 = obj->getMin();
 */
// @lc code=end
